import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'zolon_printer_platform_interface.dart';

/// An implementation of [ZolonPrinterPlatform] that uses method channels.
class MethodChannelZolonPrinter extends ZolonPrinterPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('zolon_printer');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<void> configM9200Printer(int printMode, int labelPaperWidth, int labelPaperHeight) async {
    await methodChannel.invokeMethod('configM9200Printer', {
      "printMode": printMode,
      "labelPaperWidth": labelPaperWidth,
      "labelPaperHeight": labelPaperHeight
    });
  }

  @override
  Future<void> m9200PrintLabel(String labelText, int paperWidth, int paperHeight) async {
    await methodChannel.invokeMethod('m9200PrintLabel', {
      "labelText": labelText,
      "paperWidth": paperWidth,
      "paperHeight": paperHeight
    });
  }

  @override
  Future<void> m9200PrintTicket({
    required String orderJSON,
    required String shopJSON,
    required String printerJSON,
    required String ticketType,
    bool isDebugMode = false
  }) async {
    await methodChannel.invokeMethod('m9200PrintTicket', {
      "orderJSON": orderJSON,
      "shopJSON": shopJSON,
      "printerJSON": printerJSON,
      "ticketType": ticketType,
      "isDebugMode": isDebugMode
    });
  }
}
